package com.bole.data;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    //成功的方法
    public static Result ok(){
        return new Result(ResultEnum.OK.getCode(),ResultEnum.OK.getValue());
    }
    //失败的方法
    public static Result fail(){
        return new Result(ResultEnum.FAIL.getCode(),ResultEnum.FAIL.getValue());
    }

    //根据传入的不同值，响应不同的结果
    public static Result response(ResultEnum result){
        return new Result(result.getCode(),result.getValue());
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

}
